home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / eiffel / smalleif.97 / se.t / SmallEiffel / lib_std / real_ref.e < prev    next >
Encoding:
Text File  |  1996-05-02  |  1.9 KB  |  101 lines

  1. -- Part of SmallEiffel -- Read DISCLAIMER file -- Copyright (C) 
  2. -- Dominique COLNET and Suzanne COLLIN -- colnet@loria.fr
  3. --
  4. class REAL_REF
  5.  
  6. inherit
  7.    NUMERIC
  8.       redefine
  9.      infix "+", infix "-", infix "*", infix "/", infix "^",
  10.      prefix "+", prefix "-", valid_divisor, one, zero
  11.       end;
  12.    COMPARABLE
  13.       redefine
  14.      infix "<", compare
  15.       end;
  16.  
  17. creation {ANY}
  18.    make
  19.  
  20. feature {ANY}
  21.  
  22.    item: REAL;
  23.  
  24.    make(value: REAL) is
  25.       do
  26.      item := value
  27.       end;
  28.    
  29.    infix "+" (other: like Current): like Current is
  30.      -- Add `other' to Current.
  31.       do
  32.      !!Result.make (item + other.item)
  33.       end;
  34.  
  35.    infix "-" (other: like Current): like Current is
  36.      -- Subtract `other' from Current.
  37.       do
  38.      !!Result.make (item - other.item);
  39.       end;
  40.  
  41.    infix "*" (other: like Current): like Current is
  42.      -- Multiply `other' by Current.
  43.       do
  44.      !!Result.make (item * other.item)
  45.       end;
  46.  
  47.    infix "/" (other: like Current): like Current is
  48.      -- Divide Current by `other'.
  49.       do
  50.      !!Result.make (item / other.item)
  51.       end;
  52.  
  53.    infix "^" (exp: INTEGER): like Current is
  54.      -- Raise Current to `exp'-th power.
  55.       do
  56.      !!Result.make (item ^ exp)
  57.       end;
  58.  
  59.    prefix "+" : like Current is
  60.       do
  61.      !!Result.make (item)
  62.       end;
  63.  
  64.    prefix "-" : like Current is
  65.       do
  66.      !!Result.make (-item);
  67.       end;
  68.  
  69.    infix "<" (other: like Current): BOOLEAN is
  70.      -- Is Current less than `other'?
  71.       do
  72.      Result := item < other.item
  73.       end;
  74.  
  75.    compare (other: like Current): INTEGER is
  76.      -- Compare Current with `other'.
  77.      -- '<' <==> Result < 0
  78.      -- '>' <==> Result > 0
  79.      -- Otherwise Result = 0
  80.       do
  81.      Result := item.compare (other.item)
  82.       end;
  83.  
  84.    valid_divisor (other: like Current): BOOLEAN is
  85.       do
  86.      Result := (other.item /= 0.0)
  87.       end;
  88.  
  89.    one: like Current is
  90.       do
  91.      !!Result.make (1.0)
  92.       end;
  93.  
  94.    zero: like Current is
  95.       do
  96.      !!Result.make (0.0)
  97.       end;
  98.  
  99. end -- class REAL_REF
  100.  
  101.